package by.euanpa.android.grodnobusstop.utils;

import android.database.Cursor;

public class CursorUtils {

	public static String getString(String key, Cursor cursor){
		if(isAvailable(cursor)){
			return cursor.getString(cursor.getColumnIndex(key));
		}
		return null;
	}
	
	public static int getInt(String key, Cursor cursor) {
		if(isAvailable(cursor)){
			return cursor.getInt(cursor.getColumnIndex(key));
		}
		return -1;
	}
	
	public static void close(Cursor cursor){
		if(isAvailable(cursor)){
			cursor.close();
		}
	}
	
	public static boolean isAvailable(Cursor cursor){
		return cursor != null && !cursor.isClosed();
	}
	
	public static boolean isEmpty(Cursor cursor){
		return cursor == null || cursor.getCount() == 0;
	}
}
